package univer.oko.olap.report;

import univer.oko.query.QueryResult;

import java.util.ArrayList;
import java.util.Map;
import java.io.Serializable;

/**
 * @author Vanin Yuri
 * Date: 25.03.2009
 */
public class ReportData implements Serializable {
    private ArrayList<String> columns;
    private ArrayList<ArrayList> rows;
    private ArrayList<QueryResult.DataType> types;

    public ReportData(int rowCount) {
        columns = new ArrayList<String>();
        rows = new ArrayList<ArrayList>();
        types = new ArrayList<QueryResult.DataType>();
        for (int i=0; i<rowCount; i++)
            rows.add(new ArrayList());
    }

    public int getColumnCount() {
        return columns.size();
    }

    public int getRowCount() {
        return rows.size();
    }

    public void addColumn(String colName, QueryResult.DataType type) {
        columns.add(colName);
        types.add(type);
    }

    public void addValueToRow(int rowNumber, Object value) {
        rows.get(rowNumber).add(value);
    }

    public String getColumn(int index) {
        return columns.get(index);
    }

    public Object getValueAt(int row, int col) {
        return rows.get(row).get(col);
    }

    public void setValueAt(int row, int col, Object value) {
        rows.get(row).set(col,value);
    }

    // ExcelReportWriter compatibility functions
    public ArrayList<ArrayList> getData() {
        return rows;
    }

    public ArrayList<String> getHeaders() {
        return columns;
    }

    public ArrayList<QueryResult.DataType> getTypes() {
        return types;
    }
    // -----------------------------------------

    public void LocalizeColumns(Map<String, String> rules) {
        ArrayList<String> newCols = new ArrayList<String>();
        for(String col: columns) {
            String s = col;
            for(String rule: rules.keySet())
                s = s.replace(rule, rules.get(rule));
            newCols.add(s);
        }
        columns = newCols;
    }
}
